<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  #div1 {
    width: 100px;
    height: 100px;
    background: #CCC;
    position: absolute;
  }
</style>
<script>

  document.onkeydown = function (event) {
    let div = document.getElementById("div1")

    if (event.key == "ArrowUp") {
      div.style.top = div.offsetTop - 10 + "px"
    } else if (event.key == "ArrowDown") {
      div.style.top = div.offsetTop + 10 + "px"
    } else if (event.key == "ArrowLeft") {
      div.style.left = div.offsetLeft - 10 + "px"
    } else if (event.key == "ArrowRight") {
      div.style.left = div.offsetLeft + 10 + "px"
    }
  }


</script>

<body>
  <div id="div1"></div>

</body>

</html>